package com.xujc.entity;

import org.springframework.context.annotation.Lazy;

import javax.persistence.*;
import java.util.Collection;

/**
 * Created by xujc on 6/16/15.
 */
@Entity
@Table(name = "user", schema = "", catalog = "test")
@Lazy(value = false)
public class UserEntity {
    private int mUId;
    private String mEmail;
    private String mUserName;
    private String mPassword;
    private Collection<DiscuseEntity> mDiscusesByUId;
    private Collection<ReviewEntity> mReviewsByUId;

    @Id
    @Column(name = "u_id")
    @GeneratedValue
    public int getUId() {
        return mUId;
    }

    public void setUId(int UId) {
        mUId = UId;
    }

    @Basic
    @Column(name = "email")
    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    @Basic
    @Column(name = "user_name")
    public String getUserName() {
        return mUserName;
    }

    public void setUserName(String userName) {
        mUserName = userName;
    }

    @Basic
    @Column(name = "password")
    public String getPassword() {
        return mPassword;
    }

    public void setPassword(String password) {
        mPassword = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UserEntity that = (UserEntity) o;

        if (mEmail != null ? !mEmail.equals(that.mEmail) : that.mEmail != null) return false;
        if (mUserName != null ? !mUserName.equals(that.mUserName) : that.mUserName != null) return false;
        if (mPassword != null ? !mPassword.equals(that.mPassword) : that.mPassword != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = mEmail != null ? mEmail.hashCode() : 0;
        result = 31 * result + (mUserName != null ? mUserName.hashCode() : 0);
        result = 31 * result + (mPassword != null ? mPassword.hashCode() : 0);
        return result;
    }

    @OneToMany(mappedBy = "userByUId")
    public Collection<DiscuseEntity> getDiscusesByUId() {
        return mDiscusesByUId;
    }

    public void setDiscusesByUId(Collection<DiscuseEntity> discusesByUId) {
        mDiscusesByUId = discusesByUId;
    }

    @OneToMany(mappedBy = "userByUId")
    public Collection<ReviewEntity> getReviewsByUId() {
        return mReviewsByUId;
    }

    public void setReviewsByUId(Collection<ReviewEntity> reviewsByUId) {
        mReviewsByUId = reviewsByUId;
    }
}
